package xl.net
{
	import flash.net.NetConnection;
	import flash.net.Responder;

	public class AmfConnect
	{
		private var _gateWay:String = 'http://www.srcms.com/srcms/yii/demos/dbTest/index.php?r=Amf';
		private var _connect:NetConnection = new NetConnection();
		private var _responder:Responder;
		private var _currentModel:AmfModel;

		public function AmfConnect()
		{
			_connect.connect(_gateWay);
			_responder = new Responder(onOkCall,onFaultCall);
		}
		
		public function call($model:AmfModel):void
		{
			_currentModel = $model;
			_connect.call($model.serverClass+"."+$model.method, _responder,$model.param);
		}
		
		private function onOkCall($param:Object):void
		{
			if(_currentModel.okCall!=null)
			{
				_currentModel.okCall.call(null,$param);
			}
		}
		
		private function onFaultCall($param:Object):void
		{
			if(_currentModel.faultCall!=null)
			{
				_currentModel.faultCall.call(null,$param);
			}			
		}
		
	}
}